package com.zhuzi.common.utils.excel;


import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.HyperlinkData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

/**
 * @Created by yd
 * <p>自定义超链接
 * 在需要的属性上添加注解 @ExcelProperty(value = "入职时间", converter = HyperlinkConverter.class)
 */
public class HyperlinkConverter implements Converter<String> {

    @Override
    public Class<String> supportJavaTypeKey() {
        return String.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }


    @Override
    public WriteCellData<?> convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        
        // 设置超链接
        WriteCellData<String> hyperlink = new WriteCellData<>(value);
        HyperlinkData hyperlinkData = new HyperlinkData();
        hyperlinkData.setAddress(value);
        hyperlinkData.setHyperlinkType(HyperlinkData.HyperlinkType.URL);

        hyperlink.setHyperlinkData(hyperlinkData);

        return hyperlink;
    }

}


